from langchain_core.messages import HumanMessage, AIMessage, SystemMessage, filter_messages

messages = [
    SystemMessage("you are a good assistant", id="1"),
    HumanMessage("example input", id="2", name="example_user"),
    AIMessage("example output", id="3", name="example_assistant"),
    HumanMessage("real input", id="4", name="bob"),
    AIMessage("real output", id="5", name="alice"),
]

filtered_messages = filter_messages(
    messages,
    # include_names=["bob", "alice"], # 只保留包含"bob"和"alice"的消息
    # exclude_names=["example_user", "example_assistant"], # 排除包含"example_user"和"example_assistant"的消息
    include_types=[HumanMessage, AIMessage], # 只保留HumanMessage和AIMessage类型的消息
    # exclude_types=[SystemMessage], # 排除SystemMessage类型的消息
    # include_ids=["2", "5"], # 只保留包含"2"和"5"的id的消息
    # exclude_ids=["1", "3"], # 排除包含"1"和"3"的id的消息
    # exclude_tool_calls=True, # 排除包含tool_calls的消息
)

print(filtered_messages)
